﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication2;
using WindowsFormsApplication2.Model;

namespace Anata_Client
{
    public partial class frmAlokasi : Form
    {
        ArrayList karyawan;
        ArrayList transaksiLayanan;
        ArrayList transaksiProduk;
        int idTransaksiLayanan;
        object[] o;

        public frmAlokasi()
        {
            InitializeComponent();
        }

        public frmAlokasi(ref ArrayList a, ref ArrayList b, int _idTransaksiLayanan)
        {
            InitializeComponent();

            transaksiLayanan = a;
            transaksiProduk = b;
            idTransaksiLayanan = _idTransaksiLayanan;

            for (int i = 0; i < transaksiLayanan.Count; ++i)
            {
                o = (object[])transaksiLayanan[i];
                if ((int)o[1] == idTransaksiLayanan)
                    break;
            }

            karyawan = Karyawan.DaftarKaryawanArrayList((int)Form1.idCabang, (string)o[5]);
            object[] n;

            for (int i = 0; i < karyawan.Count; ++i)
            {
                n = (object[])karyawan[i];
                cmbKaryawan.Items.Add(n[1]);
                if ((string)n[1] == (string)o[4])
                    cmbKaryawan.SelectedIndex = i;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            object[] n = (object[])karyawan[cmbKaryawan.SelectedIndex];

            TransaksiLayanan t = new TransaksiLayanan();
            t.UpdateTransaksiLayanan((int)o[1], (int)n[0]);

            o[4] = n[1];

            Form5 f = new Form5(ref transaksiLayanan, ref transaksiProduk);
            f.Show();
            this.Close();
        }

        private int findTransaksiLayanan(int _idTransaksiLayanan)
        {
            object[] o;

            for (int i = 0; i < transaksiLayanan.Count; ++i)
            {
                o = (object[])transaksiLayanan[i];
                if ((int)o[1] == _idTransaksiLayanan)
                    return i;
            }

            return transaksiLayanan.Count;
        }
    }
}
